<?php

$nf = &$_l['not_found'];
$ad = &$_l['access_denyed'];
switch(@$_v['action']) {
case 'rss': include 'lib/rss.php';
break;

case 'login':
	if (ADMIN) {
		setcookie("sid", "");
		header("Location: ".$_SERVER['PHP_SELF']); 
	} else {
		if ($_s['pass'] == md5(@$_v['pass'])) {
			$sid = md5(uniqid(""));
			setcookie("sid", $sid, time() + 604800,'/');
			fsave($_s['data_dir'].'/sess.php',"w+",'<?php $_s["sid"] = "'.$sid.'"; ?>');
			header("Location: ".$_SERVER['PHP_SELF'].$_s['afterlogin']);
		}
		else include $_i['tpl_patch'].'/login_form.html';
	}
	exit();
break;

case "comment":
	if(is_numeric(@$_v['p']) && is_file($_s['posts_dir'].'/'.$_v['p'])){
		echo nae_new_comment($_v['p']);
		redirect(generate_link('p='.$_v['p']));
	}
break;//case "comment":

case "new_pag"://Дальше ниасилил
	if (ADMIN){
		if (!@$_v['title']||!@$_v['text'])echo nae_new_page(@$_v['pg']);
		else redirect(generate_link('pg='.nae_save_page($_v['title'],$_v['text'])));
	}
	else nae_exit($ad);
break;

case "del_pag":
	if (ADMIN){
		redirect($_s['base_url']);
		if(!isset($_v['pg']))nae_exit($nf);
		nae_delete_page($_v['pg']);
	}
	else nae_exit($ad);
break;

case "edit_pag":
	if (ADMIN){
		if(!isset($_v['pg'])) nae_exit($nf);
		if (@$_v['text'] && @$_v['pg'])redirect(generate_link('pg='.nae_save_page($_v['title'],$_v['text'])));
		else echo nae_edit_page($_v['pg']);
	}
	else nae_exit($ad);
break;

case "add_post":
	if (ADMIN){
		if (@$_v['title'] && @$_v['text'])
			redirect(generate_link('p='.nae_save_post(time(),$_v['title'],$_v['text'],$_v['tags'])));
		else echo nae_new_post();
	}
	else  nae_exit($ad);
break;

case "edit_post":
	if (ADMIN){
		if($_v['p']){
			if (@$_v['title']&&@$_v['text'])
				redirect(generate_link('p='.nae_save_post($_v['p'],$_v['title'],$_v['text'],$_v['tags'])));
			else echo nae_edit_post($_v['p']);
		}
		else nae_exit($nf);
	}
	else  nae_exit($ad);
break;

case "del_post":
	if (ADMIN){
		if($_v['p']){
			nae_delete_post($_v['p']);
			redirect($_s['base_url']);
		}
		else nae_exit($nf);
	}
	else  nae_exit($ad);
break;

case "hide_comment":
	if (ADMIN){
		if($_v['p']&&is_numeric($_v['c'])){
			if(nae_comment_visible($_v['p'],$_v['c'],1)) redirect(generate_link('p='.$_v['p']));
			else echo $_l['error'];
		}
		else nae_exit($nf);
	}
	else  nae_exit($ad);
break;

case "unhide_comment":
	if (ADMIN){
		if($_v['p']&&is_numeric($_v['c'])){
			if(nae_comment_visible($_v['p'],$_v['c'],0)) redirect(generate_link('p='.$_v['p']));
			else echo $_l['error'];
		}
		else nae_exit($nf);
	}
	else  nae_exit($ad);
break;

case "del_comment":
	if (ADMIN){
		if($_v['p'] && is_numeric($_v['c'])){
			if(nae_delete_comment($_v['p'],$_v['c']))redirect(generate_link('p='.$_v['p']));
			else echo $_l['error'];
		}
		else nae_exit($nf);
	}
	else  nae_exit($ad);
break;

case 'ext':
	if (ADMIN) include 'ext/manage.php';
	else nae_exit($ad);
break;

default:

break;
}
